﻿namespace WebApplication1.API返回类
{
    /// <summary>
    /// 统一返回类
    /// </summary>
    public class APIResult<T>
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public APIEnum Code { get; set; }


        /// <summary>
        /// 描述
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// /响应数据
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        /// 成功调用的快速赋值方法
        /// </summary>
        /// <param name="msg">响应类型</param>
        /// <param name="t">响应数据</param>
        /// <returns>响应包装类的实力</returns>
        public static APIResult<T> Success(string msg, T t)
        {
            return new APIResult<T> { Code = APIEnum.成功, Message = msg, Data = t };
        }
       
        /// <summary>
        /// 重载(失败掉用的快速赋值方法)
        /// </summary>
        /// <param name="code"></param>
        /// <param name="msg">响应类型</param>
        /// <param name="t">响应数据</param>
        /// <returns>响应包装类的实力</returns>
        public static APIResult<T> Fail(string msg)
        {
            return new APIResult<T> { Code = APIEnum.失败, Message = msg };
        }
    }
}
